plugins["Kick"] = "kontrol_kick"

if SERVER then
	function Kick(pl, cmd, args)
		if !pl:KAdmin() && !pl:KModerator() then return end
		
		local target = player.GetByUniqueID(args[1])
		if !target then return end
		if (target:KAdmin() || target:KModerator()) && !pl:KOwner() then return end
		
		local admin = pl
		local reason = args[2]
		
		if ValidEntity(target) then
			target:Kick(reason)
			PrintMessage(HUD_PRINTTALK, admin:Name() .. " kicked " .. target:Name() .. ": " .. reason)
		end
	end
	concommand.Add("sv_kontrol_kick", Kick)
end

if CLIENT then
	function KickMenu(pl, cmd, args)
		local id = args[1]
	
		local menu = vgui.Create("KFrame2")
		menu:SetSize(300, 87)
		menu:SetPos(ScrW() / 2 - 150, ScrH() / 2 - 43)
		menu:SetTitle("Kick Options")
		menu:SetDraggable(true)
		menu:ShowCloseButton(true)
		menu:SetSizable(false)
		menu:MakePopup()
		
		local reason = vgui.Create("DTextEntry", menu)
		reason:SetSize(280, 20)
		reason:SetPos(10, 32)
		reason:SetValue("Reason for Kick")
		
		local accept = vgui.Create("KButton", menu)
		accept:SetSize(100, 20)
		accept:SetPos(100, 57)
		accept:SetText("Accept")
		accept.DoClick = function()
			local kickReason = reason:GetValue()
			if kickReason == "Reason for Kick" then kickReason = "No reason specified" end
			
			RunConsoleCommand("sv_kontrol_kick", id, kickReason)
			menu:Close()
			RefreshPlayerlist()
		end
	end
	concommand.Add("kontrol_kick", KickMenu)
end